package com.prs.crm.domain.flow;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.BaseEntity;

@Entity
@Table(name="flow_processnode")
public  class WorkFlowProcessNode extends BaseEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4058448999126698731L;

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@ManyToOne
	@org.hibernate.annotations.ForeignKey(name="none") 
	private WorkFlowProcess flowProcess;
	

	@ManyToOne
	private WorkFlowInstanceNode instanceNode;
	
	/**
	 * 流程指定的
	 */
	private WorkFlowHandler  handler;//经手人

	@OneToMany(fetch=FetchType.LAZY,mappedBy="processNode",cascade = CascadeType.ALL)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<WorkFlowProcessNodeDetail> details;
	
	
	private Integer status;
	
	private Integer result;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setInstanceNode(WorkFlowInstanceNode instanceNode) {
		this.instanceNode = instanceNode;
	}

	public WorkFlowInstanceNode getInstanceNode() {
		return instanceNode;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getStatus() {
		return status;
	}

	public void setFlowProcess(WorkFlowProcess flowProcess) {
		this.flowProcess = flowProcess;
	}

	public WorkFlowProcess getFlowProcess() {
		return flowProcess;
	}


	public void setHandler(WorkFlowHandler handler) {
		this.handler = handler;
	}

	public WorkFlowHandler getHandler() {
		return handler;
	}

	public void setDetails(Set<WorkFlowProcessNodeDetail> details) {
		this.details = details;
	}

	public Set<WorkFlowProcessNodeDetail> getDetails() {
		return details;
	}

	public void setResult(Integer result) {
		this.result = result;
	}

	public Integer getResult() {
		return result;
	}
	
	public void addDetail(WorkFlowProcessNodeDetail detail)
	{
		if (details ==null)
		{
			details = new HashSet<WorkFlowProcessNodeDetail>();
		}
		detail.setProcessNode(this);
		details.add(detail);
	}
}
